package netty.http.xml.codec;

import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.FullHttpRequest;

import java.util.List;

import static io.netty.handler.codec.http.HttpResponseStatus.BAD_REQUEST;

/**
 * @program JavaBase
 * @description: 服务端解码器
 * @author: zhanglu
 * @create: 2021-10-28 11:14:00
 */
public class HttpServerXmlDecoder extends AbstractHttpXmlDecoder<FullHttpRequest> {

    @Override
    protected void decode(ChannelHandlerContext ctx, FullHttpRequest request, List<Object> list) throws Exception {
        if (!request.decoderResult().isSuccess()) {
            this.sendError(ctx, BAD_REQUEST);
            return;
        }
        String body = decode(request);
        HttpXmlRequest xmlRequest = new HttpXmlRequest(request, body);
        list.add(xmlRequest);
    }

}
